package com.mmd.common.utils;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;

public class EncrypUtils {

    //使用JDK的base64实现转码
    public static String jdkBase64Encode(String str) {
        BASE64Encoder encoder = new BASE64Encoder();
        String encode = encoder.encode(str.getBytes());
        System.out.println("encode:  " + encode);
        return encode;
    }

    //使用JDK的base64实现解码
    public static String jdkBase64Decode(String str) {
        String decode = "";
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            decode = new String(decoder.decodeBuffer(str), "UTF-8");
            System.out.println("decode:  " + decode);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return decode;
    }

    public static void main(String[] args) {
        String str = jdkBase64Encode("yasir");
        jdkBase64Decode(str);
//        new String(decoder.decodeBuffer(encodedText), "UTF-8")
    }
}
